package com.woniu.apipassenger.controller;

import com.woniu.apipassenger.service.UserService;
import com.woniu.internalcommon.dto.PassengerUser;
import com.woniu.internalcommon.dto.ResponseResult;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/users")
    public ResponseResult getUser(HttpServletRequest request){

        // 从http请求中获取 accessToken
        String accessToken = request.getHeader("Authorization");

        return userService.getUserByAccessToken(accessToken);

    }
    @PostMapping("/register-passenger")
    public ResponseResult registerPassenger(@RequestBody PassengerUser passengerUser) {
        System.out.println(passengerUser.getPassengerGender()+" "+passengerUser.getPassengerPhone()+" "+passengerUser.getPassengerName());
        System.out.println(userService.registerPassenger(passengerUser.getPassengerName(), passengerUser.getPassengerPhone(), passengerUser.getPassengerGender()));
        return userService.registerPassenger(passengerUser.getPassengerName(), passengerUser.getPassengerPhone(), passengerUser.getPassengerGender());
    }
}
